﻿using ServiceStack.Redis;
using System;
using System.Threading.Tasks;
using System.Web.Configuration;

namespace SDAU.GCT.OA.Common.Cache
{
    public  class RedisCacheWriter : ICacheWriter
    {
        public RedisClient redisClient { get; set; }
        public  RedisCacheWriter()
        {
            string server = WebConfigurationManager.AppSettings["Rediscacheserver"];
            string host = server.Split(':')[0];
            int port =Int32.Parse(server.Split(':')[1]);
            redisClient = new RedisClient(host,port);

        }

      
        public object getCache(string key)
        {
           return  redisClient.GetValue(key);
        }



        void ICacheWriter.Addcache(string key, object value, DateTime exadate)
        {
            redisClient.Add(key, value, exadate);
        }

        void ICacheWriter.Addcache(string key, object value)
        {
            redisClient.Add(key, value);
        }

        void ICacheWriter.SetCache(string key, object value, DateTime exadate)
        {
            redisClient.Set(key, value, exadate);
        }

        void ICacheWriter.SetCache(string key, object value)
        {
            redisClient.Set(key, value);
        }
    }
}
